package com.ruoyi.teaching.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teaching.domain.TeachingClassification;
import com.ruoyi.teaching.service.ITeachingClassificationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分类信息Controller
 * 
 * @author ruoyi
 * @date 2022-03-21
 */
@RestController
@RequestMapping("/teaching/classification")
public class TeachingClassificationController extends BaseController
{
    @Autowired
    private ITeachingClassificationService teachingClassificationService;

    /**
     * 查询分类信息列表
     */
    @PreAuthorize("@ss.hasPermi('teaching:classification:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeachingClassification teachingClassification)
    {
        startPage();
        List<TeachingClassification> list = teachingClassificationService.selectTeachingClassificationList(teachingClassification);
        return getDataTable(list);
    }

    /**
     * 导出分类信息列表
     */
    @PreAuthorize("@ss.hasPermi('teaching:classification:export')")
    @Log(title = "分类信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeachingClassification teachingClassification)
    {
        List<TeachingClassification> list = teachingClassificationService.selectTeachingClassificationList(teachingClassification);
        ExcelUtil<TeachingClassification> util = new ExcelUtil<TeachingClassification>(TeachingClassification.class);
        util.exportExcel(response, list, "分类信息数据");
    }

    /**
     * 获取分类信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:classification:query')")
    @GetMapping(value = "/{classificationId}")
    public AjaxResult getInfo(@PathVariable("classificationId") Long classificationId)
    {
        return AjaxResult.success(teachingClassificationService.selectTeachingClassificationByClassificationId(classificationId));
    }

    /**
     * 新增分类信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:classification:add')")
    @Log(title = "分类信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeachingClassification teachingClassification)
    {
        return toAjax(teachingClassificationService.insertTeachingClassification(teachingClassification));
    }

    /**
     * 修改分类信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:classification:edit')")
    @Log(title = "分类信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeachingClassification teachingClassification)
    {
        return toAjax(teachingClassificationService.updateTeachingClassification(teachingClassification));
    }

    /**
     * 删除分类信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:classification:remove')")
    @Log(title = "分类信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{classificationIds}")
    public AjaxResult remove(@PathVariable Long[] classificationIds)
    {
        return toAjax(teachingClassificationService.deleteTeachingClassificationByClassificationIds(classificationIds));
    }
}
